package my.maven.project.spiderproc.common;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Scope;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component 
@Scope
@Aspect
public class LockAop {

	private static Lock lock = new ReentrantLock(true);

	@Pointcut(value = "@annotation(my.maven.project.spiderproc.common.TransAop)")
	public void pointcut() {

	}
	

	/**
	 * order代理级别LOWEST_PRECEDENCE表示最内层
	 * @param joinPoint
	 * @return
	 */
	@Order(value = Ordered.LOWEST_PRECEDENCE)
	@Around("pointcut()")
	public Object around(ProceedingJoinPoint joinPoint) {
		lock.lock();
		Object obj = null;
		try {
			obj = joinPoint.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			lock.unlock();
		}
		return obj;
	}

}
